package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("分页查询护理项目")
    public ResponseResult<PageResponse<NursingProjectVo>> page(
            @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页数量", defaultValue = "5") @RequestParam(defaultValue = "5") Integer pageSize,
            @ApiParam(value = "项目名称") String name,
            @ApiParam(value = "状态") Integer status
    ){
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.page(pageNum, pageSize,name,status);
        log.info("name: {},status: {},pageNum: {},pageSize: {}",name,status,pageNum,pageSize);
        return ResponseResult.success(pageResponse);
    }

    @PostMapping
    @ApiOperation("添加护理项目")
    public ResponseResult add(@ApiParam(value = "护理项目信息") @RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.add(nursingProjectDto);
        return success();
    }

    @GetMapping("/all")
    @ApiOperation("获取所有护理项目")
    public ResponseResult getAll(){
        List<NursingProjectVo> list =  nursingProjectService.getAll();
        return success(list);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID获取护理项目")
    public ResponseResult getById(@ApiParam(value = "项目ID") @PathVariable Long id){
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return success(nursingProjectVo);
    }

    @PutMapping
    @ApiOperation("更新护理项目")
    public ResponseResult update(@ApiParam(value = "护理项目信息") @RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.update(nursingProjectDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据ID删除护理项目")
    public ResponseResult deleteById(@ApiParam(value = "项目ID") @PathVariable Long id){
        nursingProjectService.deleteById(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("更新护理项目状态")
    public ResponseResult updateStatus(
            @ApiParam(value = "项目ID") @PathVariable Long id,
            @ApiParam(value = "状态") @PathVariable int status
    ){
        nursingProjectService.updateStatus(id,status);
        return success();
    }
}
